package main
import(
	//"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)
type Article struct{
	Title string `json:"title"`
	Desc string	`json:"desc"`
	Content string `json:"content"`
}
func main(){
	r:=gin.Default()
	r.GET("/",func(c *gin.Context){
		c.String(200,"这是一个GET请求返回的数据")
	})
	r.GET("/json",func(c *gin.Context){
		c.JSON(200,map[string]interface{}{
			"sucess":true,
			"msg":"你好 gin",
		})
	})
	r.GET("json1",func(c *gin.Context){
		c.JSON(http.StatusOK,gin.H{
			"姓名":"岳永永",
			"Age":20,
		})
	})
	r.GET("json2",func(c *gin.Context){
		a:=&Article{
			Title:"人民万岁",
			Desc:"伟大的劳动人民万岁",
			Content:"为中华之崛起而读书",
		}
		c.JSON(http.StatusOK,a)
	})
	//jsonp解决跨域请求
	//将返回的json对象作为参数传给回调函数?callback=func
	r.GET("/jsonp",func(c *gin.Context){
		a:=Article{
			Title:"自然",
			Desc:"人与自然",
			Content:"人与自然和谐相处",
		}
		c.JSONP(http.StatusOK,a)
	})
	r.GET("/xml",func(c *gin.Context){
		c.XML(http.StatusOK,map[string]interface{}{
			"姓名":"yyy",
			"Age":28,
			"gender":"male",
		})
		a:=Article{
			Title:"hhh",
			Desc:"I have a dream",
			Content:"int the future",
		}
		c.XML(http.StatusOK,a)
	})
	r.Run(":9000")
}